﻿/*********************************************************************
 *
 *                             NOTICE
 *               COPYRIGHT (c) 2012 Panoscopix Software, Inc.
 *                UNPUBLISHED - ALL RIGHTS RESERVED
 * 
 *      This program is confidential, proprietary, and a trade
 *   secret of Panoscopix Software, Inc. The receipt or possession of
 *     this program does not convey any rights to reproduce or
 *      disclose its contents, or to manufacture, use, or sell
 *       anything that it may describe, in whole or in part, 
 *   without the specific written consent of Panoscopix Software, Inc.
 *
 * Emulates a context for printing to the console.  Has indent level.
 * 
 *******************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using FileSystem;

namespace FileSystem.Utility
{
    class PrintContextImpl : IPrintContext
    {
	    private int indentLevel;
	    private String indentString;
	
	    public PrintContextImpl() {
		    indentLevel = 0;
		    calcIndentString();
	    }
	
	    public void increaseIndent() {
		    indentLevel++;
		    calcIndentString();
	    }
	
	    public void decreaseIndent() {
		    if (0 == indentLevel) {
			    ConsoleOutUtil.println("***ERROR:  Called PrintingContext.decreaseIndent below 0; ignoring.");
			    return;
		    }
		    indentLevel--;
		    calcIndentString();
	    }
	
	    public int getIndentLevel() {
		    return indentLevel;
	    }
	
	    public String getIndentString() {
		    return indentString;
	    }
	
	    public String getFormattedString(String core) {
		    return indentString + core + Environment.NewLine;
	    }
	
	    private void calcIndentString() {
		    indentString = "";
		    for (int i = 0; i < indentLevel; i++) indentString += "   ";
	    }
    }
}
